using RxjhServer.DbClss;
using System;

namespace RxjhServer
{
	public class BOSS地图
	{
		private int _ID;

		private int _MIP_ID;

		private string _MAP_NAME;

		private int _BOSS_ID;

		private string _BOSS_NAME;

		private int _DROP_ID;

		private string _DROP_NAME;

		private int _TIMER;

		private int _X;

		private int _Y;

		private bool _bcanmove;

		public int ID
		{
			get
			{
				return _ID;
			}
			set
			{
				_ID = value;
			}
		}

		public int 地图ID
		{
			get
			{
				return _MIP_ID;
			}
			set
			{
				_MIP_ID = value;
			}
		}

		public string 地图名字
		{
			get
			{
				return _MAP_NAME;
			}
			set
			{
				_MAP_NAME = value;
			}
		}

		public int 怪物ID
		{
			get
			{
				return _BOSS_ID;
			}
			set
			{
				_BOSS_ID = value;
			}
		}

		public string 怪物名字
		{
			get
			{
				return _BOSS_NAME;
			}
			set
			{
				_BOSS_NAME = value;
			}
		}

		public int 携带物品ID
		{
			get
			{
				return _DROP_ID;
			}
			set
			{
				_DROP_ID = value;
			}
		}

		public string 携带物品名字
		{
			get
			{
				return _DROP_NAME;
			}
			set
			{
				_DROP_NAME = value;
			}
		}

		public int 出现时间
		{
			get
			{
				return _TIMER;
			}
			set
			{
				_TIMER = value;
			}
		}

		public int 坐标X
		{
			get
			{
				return _X;
			}
			set
			{
				_X = value;
			}
		}

		public int 坐标Y
		{
			get
			{
				return _Y;
			}
			set
			{
				_Y = value;
			}
		}

		public bool 是否可以进入
		{
			get
			{
				return _bcanmove;
			}
			set
			{
				_bcanmove = value;
			}
		}

		public static bool boss地图是否开启(string mapName)
		{
			bool result = false;
			try
			{
				if (World.BOSS设置list.Count == 0)
				{
					return result;
				}
				foreach (BOSS地图 value in World.BOSS设置list.Values)
				{
					if (mapName == value.地图名字 && value.是否可以进入)
					{
						result = true;
						break;
					}
				}
			}
			catch (Exception ex)
			{
				Form1.WriteLine(1, "boss地图是否开启 错误" + ex?.ToString());
			}
			return result;
		}

		public static bool cheekBossMap(int nMapID)
		{
			bool result = false;
			try
			{
				if (World.BOSS设置list.Count == 0)
				{
					return result;
				}
				foreach (BOSS地图 value in World.BOSS设置list.Values)
				{
					if (nMapID == value.地图ID)
					{
						result = true;
						break;
					}
				}
			}
			catch (Exception ex)
			{
				Form1.WriteLine(1, "cheekBossMap 错误" + ex?.ToString());
			}
			return result;
		}

		public static void resetBossInfo()
		{
			try
			{
				if (World.BOSS设置list.Count != 0)
				{
					foreach (BOSS地图 value in World.BOSS设置list.Values)
					{
						if (value.是否可以进入)
						{
							World.AddNpc(value.怪物ID, value.坐标X, value.坐标Y, value.地图ID);
						}
						value.是否可以进入 = false;
					}
				}
			}
			catch (Exception ex)
			{
				Form1.WriteLine(1, "resetBossInfo 错误" + ex?.ToString());
			}
		}

		private static void moveOutBossMap()
		{
			try
			{
				if (World.BOSS设置list.Count != 0)
				{
					foreach (Players value in World.allConnectedChars.Values)
					{
						if (cheekBossMap(value.人物坐标_地图))
						{
							value.移动(529f, 1528f, 15f, 101);
						}
					}
					foreach (BOSS地图 value2 in World.BOSS设置list.Values)
					{
						World.delNpc(value2.地图ID, value2.怪物ID);
					}
				}
			}
			catch (Exception ex)
			{
				Form1.WriteLine(1, "resetBossInfo 错误" + ex?.ToString());
			}
		}

		public static void chaeckBossInfo(int thisHour)
		{
			try
			{
				if (World.BOSS设置list.Count != 0)
				{
					moveOutBossMap();
					foreach (BOSS地图 value in World.BOSS设置list.Values)
					{
						if (value.出现时间 == thisHour)
						{
							value.是否可以进入 = true;
							World.发送公告(value.地图名字 + "将在10分钟后刷新boss[" + value.怪物名字 + "]请在10分钟内使用命令[@BOSS " + value.地图名字 + "]进入");
						}
					}
				}
			}
			catch (Exception ex)
			{
				Form1.WriteLine(1, "chaeckBossInfo 错误" + ex?.ToString());
			}
		}

		public static void 更新BOSS次数()
		{
			try
			{
				RxjhClass.初始化BOSS次数();
				foreach (Players value in World.allConnectedChars.Values)
				{
					if (value.检查金符())
					{
						value.BOSS次数 = 1;
					}
					else
					{
						value.BOSS次数 = 0;
					}
				}
			}
			catch (Exception)
			{
			}
		}

		public static DropClass 获得BOSS持有物品(int nMapID, int npcID)
		{
			try
			{
				foreach (BOSS地图 value in World.BOSS设置list.Values)
				{
					if (nMapID == value.地图ID && npcID == value.怪物ID)
					{
						return new DropClass
						{
							FLD_NAME = value.携带物品名字,
							FLD_PID = value.携带物品ID
						};
					}
				}
			}
			catch (Exception)
			{
			}
			return null;
		}
	}
}
